//
//  ContactImformationCell.m
//  DingDongXiChe
//
//  Created by wtjr on 2017/11/28.
//  Copyright © 2017年 xieyingze. All rights reserved.
//

#import "ContactImformationCell.h"
#import "CustomReuseCellView.h"

@interface ContactImformationCell()

@property (nonatomic, strong) UIView *mainView;

@property (nonatomic, strong) CustomReuseCellView *userNameView;

@property (nonatomic, strong) CustomReuseCellView *userPhoneView;

@property (nonatomic, strong) CustomReuseCellView *userLocationView;

@end

@implementation ContactImformationCell

#pragma mark - ********************生命周期********************

+ (instancetype)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath {
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    static NSString *cellId = @"ContactImformationCell";
    ContactImformationCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil) {
        cell = [[ContactImformationCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    return cell;
}

#pragma mark - 内部方法

- (void)initSubView {
    self.backgroundColor = kCOLOR_tableView;
    [self addSubview:self.mainView];
    [self.mainView addSubview:self.userNameView];
    [self.mainView addSubview:self.userPhoneView];
    [self.mainView addSubview:self.userLocationView];
}

- (void)autoLayoutSubviews {
    [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@0).insets(UIEdgeInsetsMake(5, 5, 5, 5));
    }];
    [self.userNameView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(@0);
        make.height.equalTo(@(kUI_CellHeight));
    }];
    [self.userPhoneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.top.equalTo(self.userNameView.mas_bottom);
        make.height.equalTo(self.userNameView);
    }];
    [self.userLocationView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.top.equalTo(self.userPhoneView.mas_bottom);
        make.height.equalTo(self.userNameView);
    }];
}

#pragma mark - 点击事件

#pragma mark - 外部方法

#pragma mark - Setter

- (void)setViewModel:(OrderViewModel *)viewModel {
    _viewModel = viewModel;
    @weakify(self);
    [[[self.userNameView.inputTextfiled rac_signalForControlEvents:UIControlEventEditingChanged] map:^id _Nullable(BaseTextField *tf) {
        return tf.text;
    }] subscribeNext:^(NSString *value) {
        @strongify(self);
        _viewModel.order_contact = value;
    }];
}

#pragma mark - Setter && Getter

- (UIView *)mainView {
    if (!_mainView) {
        _mainView = [UIView new];
        _mainView.backgroundColor = kCOLOR_white;
        [_mainView setViewShadow:kCOLOR_shadow offset:CGSizeMake(0, 0) radius:1];
    }
    return _mainView;
}

- (CustomReuseCellView *)userNameView {
    if (!_userNameView) {
        _userNameView = [CustomReuseCellView new];
        _userNameView.iconName = @"dd_package_package";
        _userNameView.title = @"联系人";
        _userNameView.cellType = kCustomCellTypeInput;
        _userNameView.showLine = YES;
    }
    return _userNameView;
}

- (CustomReuseCellView *)userPhoneView {
    if (!_userPhoneView) {
        _userPhoneView = [CustomReuseCellView new];
        _userPhoneView.iconName = @"dd_package_duration";
        _userPhoneView.title = @"联系电话";
        _userPhoneView.cellType = kCustomCellTypeInput;
        _userPhoneView.showLine = YES;
        _userPhoneView.inputTextfiled.text = [UnityTool getStringValueForKey:kUSER_phone];
    }
    return _userPhoneView;
}

- (CustomReuseCellView *)userLocationView {
    if (!_userLocationView) {
        _userLocationView = [CustomReuseCellView new];
        _userLocationView.iconName = @"dd_package_package";
        _userLocationView.title = @"所在地址";
        _userLocationView.cellType = kCustomCellTypeInput;
        _userLocationView.showLine = NO;
        _userLocationView.inputTextfiled.text = [UnityTool getStringValueForKey:kUSER_location];
    }
    return _userLocationView;
}

@end
